
package com.ctshk.sapp.ship.controller;


import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.model.TokenUser;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.ship.dto.*;
import com.ctshk.rpc.ship.req.*;
import com.ctshk.rpc.ship.service.IShipProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.time.LocalDate;
import java.util.List;

/**
 * <p>
 * 船票产品 前端控制器
 * </p>
 *
 * @author 谢诗宏
 * @since 2021-03-05
 */
@RestController
@RequestMapping("/ship-product")
@Api(value = "产品相关接口",tags = "产品API接口")
public class ShipProductController extends BaseController {

    @DubboReference
    private IShipProductService iShipProductService;

    @ApiOperation(value = "资源中心-产品设置", notes = "产品中心-新增船票产品",tags = "资源中心")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.ADD, operTitle = "新增船票产品", operDesc = "新增船票产品")
    @PostMapping("/save")
    public Result saveShipProduct(@RequestBody @Valid ShipProductReq shipProductReq) {
        TokenUser user = getCurrentUser(getRequest());
        return iShipProductService.saveShipProduct(shipProductReq, user);
    }
    @ApiOperation(value = "资源中心-预订设置", notes = "产品中心-新增船票预订设置",tags = "资源中心")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.ADD, operTitle = "新增船票预订设置", operDesc = "新增船票预订设置")
    @PostMapping("/saveBooking")
    public Result saveShipBooking(@RequestBody @Valid ShipProductReq shipProductReq) {
        TokenUser user = getCurrentUser(getRequest());
        return iShipProductService.saveShipBooking(shipProductReq, user);
    }

    @ApiOperation(value = "资源中心-船票列表查询", notes = "产品中心-船票管理列表查询",tags = "资源中心")
    @PostMapping(value = "/query-list")
    public Result<PageResponse<ShipProductDTO>> queryList(@RequestBody @Valid ShipProductPageReq shipProductPageReq) {
        return Result.success(iShipProductService.queryList(shipProductPageReq,getCurrentUser()));
    }

    @ApiOperation(value = "资源中心-提供给推广码产品列表", notes = "产品中心-提供给推广码产品列表",tags = "推广码接口")
    @PostMapping(value = "/list")
    public Result<PageResponse<ShipProductDTO>> list(@RequestBody @Valid ShipProductPageReq shipProductPageReq) {

        return Result.success(iShipProductService.queryShipList(shipProductPageReq));
    }

    @ApiOperation(value = "资源中心-查询船票产品详情", notes = "产品中心-查询船票产品详情",tags = "资源中心")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "查询船票产品详情", operDesc = "查询船票产品详情")
    @GetMapping(value = "/detail")
    public Result<ShipProductDetailDTO> queryDetail(@RequestParam(value = "id", required = true) Long id) {
        return Result.success(iShipProductService.queryDetail(id));
    }

    @ApiOperation(value = "资源中心-修改时查询船票产品详情", notes = "产品中心-修改时查询船票产品详情",tags = "资源中心")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "修改时查询船票产品详情", operDesc = "修改时查询船票产品详情")
    @GetMapping(value = "/queryProductDetail")
    public Result<ShipProductViewDetailDTO> queryProductDetail(@RequestParam(value = "id", required = true) Long id) {
        return Result.success(iShipProductService.queryProductDetail(id));
    }

    @ApiOperation(value = "资源中心-船票-审批通过产品编辑", notes = "产品中心-船票-产品编辑",tags = "资源中心")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "船票-产品编辑", operDesc = "船票-产品编辑操作")
    @PostMapping("/update")
    public Result update(@RequestBody @Valid ShipProductReq shipProductReq) {
        TokenUser user = getCurrentUser(getRequest());
        return iShipProductService.update(shipProductReq, user);
    }

    @ApiOperation(value = "产品中心-新增-编辑提交审批", notes = "产品中心-新增-编辑提交审批",tags = "资源中心")
    @PostMapping(value = "/submit")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "船票产品提交审批", operDesc = "船票产品提交审批")
    public Result submit(@RequestBody SubmitReq submitReq) {
        TokenUser user = getCurrentUser(getRequest());
        return iShipProductService.submit(submitReq, user);
    }

    @ApiOperation(value = "新增-审批", notes = "新增-审批",tags = "资源中心")
    @PostMapping(value = "/update-approval-check")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "门票售卖状态修改", operDesc = "门票售卖状态修改")
    public Result<Long> check(@RequestBody ShipProductCheckReq shipProductCheckReq) {

        return iShipProductService.check(shipProductCheckReq,getCurrentUser(getRequest()));
    }

    @ApiOperation(value = "预订中心-推荐船票列表查询", notes = "预订中心-推荐船票列表查询",tags = "预订中心")
    @GetMapping(value = "/query-recommend-list")
    public Result<List<ShipRecommendListDTO>> queryRecommendList() {
        TokenUser user = getCurrentUser(getRequest());
        return Result.success(iShipProductService.queryRecommendList(user));
    }

    @ApiOperation(value = "预订中心-船票列表查询-新接口", notes = "预订中心-船票列表查询",tags = "预订中心")
    @PostMapping(value = "/query-reserve-ship-new")
    public Result<ReserveShipProductDto> queryReserveNewShipProduct(@RequestBody  ShipProductSearchReq shipProductSearchReq) {
        TokenUser user = getCurrentUser(getRequest());
        return Result.success(iShipProductService.queryReserveNewList(shipProductSearchReq, user));
    }

    @ApiOperation(value="批量设置", notes="批量设置",tags = "产品API接口")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.ADD, operTitle = "批量设置", operDesc = "批量设置")
    @PostMapping("/batch/updateSetting")
    public Result updateSetting(@RequestBody @Valid ShipProductUpdateSettingReq shipProductUpdateSettingReq) {
        TokenUser user = getCurrentUser(getRequest());
        return iShipProductService.updateSetting(shipProductUpdateSettingReq);
    }

    @ApiOperation(value="API设置", notes="API设置",tags = "产品API接口")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.ADD, operTitle = "API设置", operDesc = "API设置")
    @PostMapping("/batch/updateApiSetting")
    public Result updateApiSetting(@RequestBody @Valid ShipProductUpdateApiSettingReq shipProductUpdateApiSettingReq) {
        TokenUser user = getCurrentUser(getRequest());
        return iShipProductService.updateApiSetting(shipProductUpdateApiSettingReq);
    }

    @ApiOperation(value="API设置详情", notes="API设置详情",tags = "产品API接口")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.ADD, operTitle = "API设置详情", operDesc = "API设置详情")
    @GetMapping("/queryApiSetting")
    public Result<ShipProductUpdateApiSettingDTO> queryApiSetting(@RequestParam(value = "id", required = true) Long id) {
        return iShipProductService.queryApiSetting(id);
    }

    @ApiOperation(value = "查询代理商列表", notes = "查询代理商列表", tags="产品API接口")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "挂账额度-查询额度", operDesc = "挂账额度-查询额度")
    @PostMapping("/query-agent-list")
    public Result<PageResponse<AgentDto>> queryAgentList(@RequestBody @Valid AgentReq req) {
        return iShipProductService.queryAgentList(req);
    }

    @ApiOperation(value = "预订-获取核对订单的基本信息", notes = "产品API接口")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "预订中心-填写订单页-根据产品id获取订单信息", operDesc = "预订中心-填写订单页-根据产品id获取订单信息")
    @PostMapping("/get-order")
    public Result<List<ShipReservationGetOrderDTO>>getOrderInfo(@RequestBody ShipReservationOrderReq shipReservationOrderReq){
        return Result.success(iShipProductService.getOrderInfo(shipReservationOrderReq));
    }
}
